import java.io.*;
import java.net.*;

class TCPClient 
{
   public static void main(String argv[]) throws Exception
   {
      String sentence;
      String modifiedSentence;
      int port = 6789;

      BufferedReader inFromUser = 
         new BufferedReader(
         new InputStreamReader(System.in));
 
      if (argv != null && argv.length > 0)
    	  port = Integer.parseInt( argv[0]);
      
      
      boolean cont = true;
      while(cont) {

      sentence = inFromUser.readLine();
          
      Socket clientSocket = new Socket("localhost", port);
    	  
      DataOutputStream outToServer =
         new DataOutputStream(
         clientSocket.getOutputStream());

      BufferedReader inFromServer =
         new BufferedReader(
         new InputStreamReader(
         clientSocket.getInputStream()));

      outToServer.writeBytes(sentence + '\n');

      modifiedSentence = inFromServer.readLine();

      System.out.println("FROM SERVER: " + modifiedSentence);

      clientSocket.close();
      }
   }
}